<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>编辑商品分类</title>
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.4/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>商品分类管理</legend>
</fieldset>

<form class="layui-form" >
    <div class="layui-form-item">
<!--        <div class="layui-inline">-->
<!--            <label class="layui-form-label" style="width: 200px;">父级分类</label>-->
<!--            <div class="layui-input-inline">-->
<!--                <select name="pid" id="classif"></select>-->
<!--            </div>-->
<!--        </div>-->

        <input type="hidden" name="id" value="{$category.id}">
        <input type="hidden" name="pid" value="{$category.pid}">
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 200px;">商品分类</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="name" autocomplete="off" value="{$category.name}"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 200px;"></label>
        <div class="layui-input-inline">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>
<script src="/static/admin/lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="/static/admin/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/admin/js/common.js" charset="utf-8"></script>
<script>
    layui.use(['form','laypage'], function () {
        var form = layui.form;


        function queryClassif() { // 请求分类 后端接口
            let url = '';
            layObj.get(url,function (res) {
                console.log(res)
            }); // 封装的ajax
            // _classif()
        }
        queryClassif(); // 获取后端分类数据

        //监听提交
        form.on('submit(demo1)', function (data) {
            console.log(data.field, '最终的提交信息')
            data = data.field
            let url = '';
            // layObj.post(url,data,function (res) {
            //
            // });
            $.ajax({
                type:'POST',
                data:data,
                url: '/admin/category/update',
                success(res){
                   if(res.status == 1){
                       layer.msg('编辑成功',function () {
                           window.location = "{:url('index')}";
                       })
                   }else {
                       layer.msg(res.message);
                       return false
                   }
                }
            })

            return false;
        });

    })
</script>
</body>
</html>
